package com.daxue.configtest.base;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jooq.Condition;

import java.util.LinkedList;

import static org.jooq.impl.DSL.trueCondition;

/**
 * @author daxue0929
 * @date 2023/3/14
 */

@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Data(staticConstructor = "where")
@Accessors(chain = true)
public class QueryConditions  extends LinkedList<Condition> {

    public static QueryConditions where(@NonNull final Condition condition) {
        return where().and(condition);
    }

    public QueryConditions and(@NonNull final Condition condition) {
        this.add(condition);
        return this;
    }

    public Condition asCondition() {
        return this.stream().reduce(Condition::and).orElse(trueCondition());
    }
}
